<template>
	<view class="content">
		<CustomNav title="肃北报灾平台"></CustomNav>
		<image src="../../static/home/banner.png" mode="widthFix" class="top-img"></image>
		<view class="top">
			<view class="tips-content">
				<view class="title FZHZGBJ">实时预警通知</view>
				<view class="line"></view>
				<view class="swiper-item">
					<swiper autoplay="true" class="notice-list" vertical="true" interval="8000">
						<swiper-item v-for="(item,index) in newsList" :key="item.id" class="notice-item"
							@click="navigate('/page_pack/notice/detail?id='+item.id)">
							<view class="news">{{item.title}}</view>
						</swiper-item>
					</swiper>
					<view class="iconfont icon-a-216gengduo-shuxiang" @click="navigate('/page_pack/notice/list')">
					</view>
				</view>
			</view>
			<view class="menu-block">
				<view class="menu-item" @click="navigate('/page_pack/contact/contact')">
					<image src="/static/home/jjlx.png" class="menu-img" mode="widthFix"></image>

				</view>
				<view class="menu-item" @click="navigate('/page_pack/animal/animal')">
					<image src="/static/home/ysdy.png" class="menu-img" mode="widthFix"></image>
				</view>
			</view>
			<view class="menu-item" @click="navigate('/page_pack/report/report')">
				<image src="/static/home/yjbz.png" class="menu-img" mode="widthFix"></image>
			</view>

			<view class="info-item">
				<view class="title-item">
					<view class="title FZHZGBJ">最新消息</view>
					<view class="more" @click="navigate('/page_pack/news/news')">更多</view>
				</view>
				<template v-if="articleList.length>0">
					<view class="info-list" v-for="item in articleList" :key="item.id"
						@click="navigate('/page_pack/animal/detail?id='+item.id+'&type=1')">
						<image :src="item.coverImage" class="img"></image>
						<view class="name-item">
							<view class="name">{{item.title}}</view>
							<view class="introduction">{{item.createTime}}</view>
						</view>
					</view>
				</template>
				<view style="text-align: center;" v-else>暂无数据</view>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		getWarningList,
		getArticleListApi
	} from '@/api/contact.js'
	import {
		getAnimalRecordList
	} from '@/api/animal.js'
	export default {
		data() {
			return {
				newsList: [],
				conf: {
					page: 1,
					limit: 4
				},
				articleList: []
			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			//onShareAppMessage 分享给朋友
			//onShareTimeline  分享到朋友圈
			// #ifdef MP
			onShareAppMessage: function(res) {
				if (res.from === 'button') {
					// 来自页面内转发按钮
					console.log(res.target)
				}
				return {
					path: '/pages/index/index'
				}
			},
			// #endif
			onShareTimeline(res) {
				let distSource = uni.getStorageSync('distSource');
				if (distSource) {
					return {
						title: '肃北报灾平台',
						path: '/pages/index/index',
						type: 0,
						query: 'id=' + distSource,
					}
				}
			},
			getList() {
				getWarningList(this.conf).then(res => {
					this.newsList = res.list
				}).finally(() => {
					uni.stopPullDownRefresh();
				})
			},
			getArticleList() {
				getArticleListApi(this.conf).then(res => {
					this.articleList = res.list
				}).finally(() => {
					uni.stopPullDownRefresh();
				})
			},
		},
		onShow() {
			this.getList()
			this.getArticleList()
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		min-height: 100vh;

		.top-img {
			width: 100%;
			margin-top: 150rpx;
		}



		.top {
			display: flex;
			flex-direction: column;
			//width: 100%;
			background: #fff;
			margin-top: -70rpx;
			border-radius: 60rpx;
			position: relative;
			padding: 30rpx;
			background: #F6F6F6;

			.tips-content {
				width: calc(100% - 40rpx);
				margin: -90rpx auto 0;
				background-color: #D83032E6;
				display: flex;
				align-items: center;
				border-radius: 20rpx;
				// position: fixed;
				// top: 13%;
				// left: 20rpx;
				z-index: 20;
				display: flex;
				align-items: center;
				padding: 30rpx 22rpx;
				color: #fff;

				.title {
					font-size: 34rpx;
					width: 206rpx;
				}

				.line {
					margin-left: 10rpx;
					width: 4rpx;
					height: 36rpx;
					border-radius: 4rpx;
					background-image: linear-gradient(#E47273, #fff, #E47273);
				}

				.swiper-item {
					width: calc(100% - 215rpx);
					height: 60rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.notice-list {
						color: #fff;
						height: 60rpx;
						margin-left: 10rpx;
						width: 100%;

						.notice-item {
							height: 60rpx;
							display: flex;
							align-items: center;

							.news {
								font-size: 30rpx;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}
						}
					}

					.iconfont {
						color: #fff;
						font-size: 34rpx;
						margin-right: 0;
					}
				}
			}

			.news-block {
				margin-top: -140rpx;

				.news-list {
					background: rgba(255, 255, 255, 0.8);
					backdrop-filter: blur(3px);
					border-radius: 20rpx;
					box-shadow: 0 0 10px 0 #dedede;
					padding: 30rpx;

					.login {
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						border-bottom: 1px solid #d4d3d3;
						align-items: center;
						height: 80rpx;

						.login-item {
							display: flex;
							flex-direction: row;
							align-items: center;

							.login-img {
								width: 50rpx;
								height: 55rpx;
								margin-right: 10rpx;
							}

							.title {
								//font-weight: bold;
								font-size: 40rpx;
							}
						}


						.btn {
							width: 240rpx;
							height: 65rpx;
							border-radius: 40rpx;
							background: #027BFD;
							color: #fff;
							display: flex;
							justify-content: center;
							align-items: center;
							margin-bottom: 15rpx;
							margin-right: 0rpx;
							font-size: 30rpx;
						}

						.revise-item {
							display: flex;
							flex-direction: row;
							align-items: center;

							.revise {
								color: #027BFD;
								font-size: 30rpx;
							}
						}
					}

					.notice {
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						height: 70rpx;
						align-items: center;
						margin-top: 20rpx;

						.title-item {
							display: flex;
							flex-direction: row;
							align-items: center;
							margin-left: 5px;

							.notice-img {
								width: 160rpx;
								height: 46rpx;
							}

							.thread {
								margin-left: 25rpx;
								width: 4rpx;
								height: 40rpx;
								border-radius: 4rpx;
								background-image: linear-gradient(#fff, #027BFD, #fff);
							}

							.title {
								font-weight: bold;
								font-size: 42rpx;
								color: #027BFD;
								margin-right: 10rpx;

							}

							.text {
								background: #027BFD;
								color: #fff;
								font-size: 40rpx;
								margin-right: 30rpx;

							}
						}

						.notice.swiper-item {
							height: 60rpx;
							//border-left: 1.5px solid #027BFD;
							margin-top: 0;

							.notice-list {
								color: #027BFD;
								width: 420rpx;
								height: 60rpx;
								margin-left: 10rpx;

								.notice-item {
									height: 60rpx;
									display: flex;
									align-items: center;

									.news {
										overflow: hidden;
										text-overflow: ellipsis;
										white-space: nowrap;
									}
								}

							}
						}
					}
				}
			}

			.menu-item {
				//width: calc((100% - 30rpx) / 2);
				// margin-bottom: 30rpx;
				margin-top: 30rpx;

				.menu-img {
					width: 100%;
					position: relative;
				}

				.title {
					margin-top: -124rpx;
					position: relative;
					display: flex;
					justify-content: center;
					padding-left: 100rpx;
					color: #fff;
					font-size: 38rpx;
					font-weight: bold;
				}
			}

			.menu-block {
				display: flex;
				// margin-top: 30rpx;

				.menu-item {
					width: calc((100% - 30rpx) / 2);
					margin-right: 30rpx;

					.menu-img {
						width: 100%;
						position: relative;
					}

					.title {
						margin-top: -124rpx;
						position: relative;
						display: flex;
						justify-content: flex-end;
						padding-right: 40rpx;
						color: #fff;
						font-size: 38rpx;
						font-weight: bold;
					}
				}

				.menu-item:last-child {
					margin-right: 0;
				}
			}

			.info-item {
				background-color: #fff;
				margin-top: 30rpx;
				border-radius: 20rpx;
				padding: 30rpx;

				.title-item {
					display: flex;
					justify-content: space-between;

					.title {
						color: #405BFF;
					}

					.more {
						font-size: 14px;
						color: #999;
					}
				}

				.info-list:last-child {
					border-bottom: none;
				}

				.info-list {
					display: flex;
					align-items: center;
					border-bottom: 1px solid #F6F6F6;
					padding: 30rpx 0;

					.img {
						width: 160rpx;
						height: 160rpx;
						border-radius: 20rpx;
						margin-right: 10rpx;
					}

					.name-item {
						width: calc(100% - 170rpx);

						.name {
							word-break: break-all;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 2;
							overflow: hidden;
							line-height: 55rpx;
							font-size: 30rpx;
						}

						.introduction {
							color: #999;
							font-size: 26rpx;
							margin-top: 20rpx;
						}
					}
				}
			}

		}
	}
</style>